//
//  CYBBaseSettingController.m
//  01-基本框架搭建
//
//  Created by apple on 16/9/3.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "CYBBaseSettingController.h"
#import "CYBStatus.h"
#import "CYBOneController.h"
#import "CYBTestTwoViewController.h"
#import "CYBStatusGroup.h"
#import "CYBTableViewCell.h"
#import "CYBStatusArrows.h"
#import "CYBStatusSwitch.h"
#import "MBProgressHUD+MJ.h"
#import "CYBProductController.h"
#import "CYBPushController.h"

@interface CYBBaseSettingController()

@end

@implementation CYBBaseSettingController

- (NSMutableArray *)status{
    if (_status == nil) {
        
        _status = [NSMutableArray array];
        
    }
    return _status;
}

- (instancetype)init{
    
    if (self = [super initWithStyle:UITableViewStyleGrouped]) {
        //
    }
    
    return self;
}

- (instancetype)initWithStyle:(UITableViewStyle)style{
    
    if (self = [super initWithStyle:UITableViewStyleGrouped]) {
        //
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.status.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    CYBStatusGroup *tatus = self.status[section];
    return tatus.items.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    CYBTableViewCell *cell = [CYBTableViewCell cellWithTableView:tableView];    //创建cell
    
    CYBStatusGroup *status = self.status[indexPath.section];
    cell.Status = status.items[indexPath.row]; //传模型
    
    return cell;    //返回cell
}

//点击某一行的时候调用的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //点击了某行取消选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    CYBStatusGroup *status = self.status[indexPath.section];
    CYBStatus *item = status.items[indexPath.row];
    
    if ([item isKindOfClass:[CYBStatusArrows class]]) {
        CYBStatusArrows *arrows = (CYBStatusArrows *)item;
        if (arrows.classVC == nil) return;  //如果类为空直接返回
        
        [self.navigationController pushViewController:[[item.classVC alloc] init] animated:YES];
        
    }else if (item.statusBlock){    //如果 statusBlock 这个block有值，就执行下面的代码
        
        item.statusBlock();
        
    }
    
}

//设置组头部标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    
    CYBStatusGroup *status = self.status[section];
    return status.header;
}

//设置组尾部标题
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
    CYBStatusGroup *status = self.status[section];
    return status.footer;
}

@end
